package com.malou.client.reportes;

import java.util.HashMap;

import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.malou.client.MalouConstants;

public class Reportes {
	
	private static ReporteServiceAsync si = GWT.create(ReporteService.class);
	private static MalouConstants constants = GWT.create(MalouConstants.class);
	public static ResumenPanel rpan;
	public static EnviarCorreoDialog correoDialog;
	
	public static void setBalanceTienda(BalanceTienda blt){
		rpan.mask(constants.cargando());
		si.getBalanceTienda(blt, new AsyncCallback<BalanceTienda>() {

			@Override
			public void onFailure(Throwable caught) {
				MessageBox.alert(constants.sistemaMarcocruzado(), constants.errorConexion(), null);
				rpan.unmask();
			}

			@Override
			public void onSuccess(BalanceTienda result) {
				
				rpan.cargarDatos(result);
				rpan.unmask();
				rpan.layout();
				
				rpan.status.hide();
				rpan.find.show();
			}
		});
	}
	
	public static void enviarEmail(String fileName, HashMap<String, Object> param, EnviarCorreo send, Integer consulta_id){
		AsyncCallback<Boolean> callback = new AsyncCallback<Boolean>(){
			
			MessageBox messageBox = new MessageBox();

			@Override
			public void onFailure(Throwable caught) {
				MessageBox.alert(constants.sistemaMarcocruzado(), constants.errorConexion(), null);
				messageBox.show();
				caught.printStackTrace();							
			}

			@Override
			public void onSuccess(Boolean result) {
				if (result){					
					correoDialog.hide();					
				}else{
					correoDialog.status.hide();
					correoDialog.getButtonBar().enable();
					messageBox.setMessage(constants.noSePudoEnviarCorreo());
					messageBox.show();
				}
				
			}
			
		};
		si.sendMail(fileName, param, send, consulta_id, callback);
	}
}
